<script setup lang="ts">
import { useWfApi } from '@/api/wf'
import { onMounted, onUnmounted, ref } from 'vue'
import mittBus from '@/utils/mitt'

const { GetOnlineUsers } = useWfApi()

const loading = ref(false)
const tableData = ref<OnlineUserRow[]>([])

const onFetch = () => {
  loading.value = true
  GetOnlineUsers()
    .then(({ data }) => {
      tableData.value = data
    })
    .finally(() => (loading.value = false))
}

onMounted(() => {
  onFetch()
  mittBus.on('onUpdateOnlineUsers', onFetch)
})

onUnmounted(() => {
  mittBus.off('onUpdateOnlineUsers')
})
</script>

<template>
  <div class="system-online layout-padding">
    <el-card class="mb5" shadow="never">
      <el-button @click="onFetch" :loading="loading">刷新</el-button>
    </el-card>
    <el-card style="height: 100%">
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column prop="userInfo.name" label="用户名称" width="100" />
        <el-table-column prop="userInfo.loginName" label="登录名" width="100" />
        <el-table-column prop="connectedOnString" label="连接时间" width="140" />
        <el-table-column prop="ipAddress" label="IP" width="120" />
        <el-table-column prop="client" label="客户端" />
      </el-table>
    </el-card>
  </div>
</template>
